/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.employee.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.chlitina.store.common.config.Global;
import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.web.BaseController;
import com.chlitina.store.modules.employee.entity.StoreEmployeeLeftComment;
import com.chlitina.store.modules.employee.service.StoreEmployeeLeftCommentService;
import com.chlitina.store.modules.expert.utils.ExpertUtils;
import com.chlitina.store.modules.sys.entity.Store;
import com.chlitina.store.modules.sys.utils.StoreUtils;

/**
 * 离职员工评价Controller
 * @author liujiang
 * @version 2013-11-12
 */
@Controller
@RequestMapping(value = Global.ADMIN_PATH+"/employee/storeEmployeeLeftComment")
public class StoreEmployeeLeftCommentController extends BaseController {

	@Autowired
	private StoreEmployeeLeftCommentService storeEmployeeLeftCommentService;
	
	@ModelAttribute
	public StoreEmployeeLeftComment get(@RequestParam(required=false) Long id) {
		if (id != null){
			return storeEmployeeLeftCommentService.get(id);
		}else{
			return new StoreEmployeeLeftComment();
		}
	}
	
	@RequestMapping(value = {"list", ""})
	public String list(StoreEmployeeLeftComment storeEmployeeLeftComment, 
			@RequestParam(required=false)Integer status,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Store store = StoreUtils.getStore();
		if (store != null){
			storeEmployeeLeftComment.setStore(store);
		}
		String searchName = request.getParameter("searchName");
        Page<StoreEmployeeLeftComment> page = storeEmployeeLeftCommentService.find(new Page<StoreEmployeeLeftComment>(request, response), searchName, status); 
        model.addAttribute("page", page);
        model.addAttribute("searchName", searchName);
        model.addAttribute("status", status);
		return "modules/employee/storeEmployeeLeftCommentList";
	}

	@RequestMapping(value = "form")
	public String form(StoreEmployeeLeftComment storeEmployeeLeftComment, Model model) {
		model.addAttribute("employeeMap", ExpertUtils.getLeaveEmployee());
		model.addAttribute("storeEmployeeLeftComment", storeEmployeeLeftComment);
		return "modules/employee/storeEmployeeLeftCommentForm";
	}

	@RequestMapping(value = "save")
	public String save(StoreEmployeeLeftComment storeEmployeeLeftComment, Model model, RedirectAttributes redirectAttributes) {
		storeEmployeeLeftComment.setStore(StoreUtils.getStore());
		storeEmployeeLeftComment.setComment_date(new Date());
		if (!beanValidator(model, storeEmployeeLeftComment)){
			return form(storeEmployeeLeftComment, model);
		}
		storeEmployeeLeftCommentService.save(storeEmployeeLeftComment);
		addMessage(redirectAttributes, "保存离职员工评价成功");
		return "redirect:"+Global.ADMIN_PATH+"/employee/storeEmployeeLeftComment/";
	}
	
	@RequestMapping(value = "delete")
	public String delete(Long id, RedirectAttributes redirectAttributes) {
		storeEmployeeLeftCommentService.delete(id);
		addMessage(redirectAttributes, "删除离职员工评价成功");
		return "redirect:"+Global.ADMIN_PATH+"/employee/storeEmployeeLeftComment/";
	}

}
